package demoMod.invincibleOne.cards.invincible;

import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.actions.SelectCardInCardGroupAction;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.interfaces.IOnAddToMasterDeck;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;

public class MoreIsBetter extends AbstractInvincibleCard implements IOnAddToMasterDeck {
    public static final String ID = InvincibleOneMod.makeID("MoreIsBetter");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/MoreIsBetter.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = -2;

    public MoreIsBetter() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.modifier = new ExhaustAtStartOfCombatMod();
        CardModifierManager.addModifier(this, modifier);
        this.tags.add(CardTagsEnum.ALERT);
        this.baseMagicNumber = this.magicNumber = 2;
    }

    @Override
    public void onAddToMasterDeck() {
        InvincibleOneMod.addToBot(new SelectCardInCardGroupAction(1, c -> c.rarity == CardRarity.COMMON, c -> {
            float displayCount = 0.0F;
            for (int i=0;i<magicNumber;i++) {
                AbstractDungeon.topLevelEffectsQueue.add(new ShowCardAndObtainEffect(c.makeStatEquivalentCopy(), (float) Settings.WIDTH / 3.0F + displayCount, (float)Settings.HEIGHT / 2.0F, false));
                displayCount += (float)Settings.WIDTH / 6.0F;
            }
        }, AbstractDungeon.player.masterDeck, SelectCardInCardGroupAction.TEXT[3]));
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            upgradeMagicNumber(1);
            if (AbstractDungeon.player != null && AbstractDungeon.player.masterDeck.contains(this)) {
                InvincibleOneMod.addToBot(new SelectCardInCardGroupAction(1, c -> c.rarity == CardRarity.COMMON, c ->
                        AbstractDungeon.topLevelEffectsQueue.add(new ShowCardAndObtainEffect(c.makeStatEquivalentCopy(), (float) Settings.WIDTH / 2.0F, (float)Settings.HEIGHT / 2.0F, false)),
                        AbstractDungeon.player.masterDeck, SelectCardInCardGroupAction.TEXT[3]));
            }
        };
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }
}
